package com.education.serviceedu.controller;


import com.education.commonutils.ResultAjax;
import com.education.serviceedu.entity.subject.OneSubject;
import com.education.serviceedu.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author zwr
 * @since 2021-05-23
 */
@RestController
@RequestMapping("/serviceedu/subject")
@CrossOrigin
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    /**
     * 添加课程分类
     * @param file 获取上传过来文件，把文件内容读取出来
     * @return
     */
    @PostMapping("addSubject")
    public ResultAjax addSubject(MultipartFile file){
        //上传过来excel文件
        eduSubjectService.saveSubject(file,eduSubjectService);
        return ResultAjax.success();
    }

    /**
     * 课程分类列表（树形）
     * @return
     */
    @GetMapping("getAllSubject")
    public ResultAjax getAllSubject(){
        //list集合泛型是一级分类
        List<OneSubject> list = eduSubjectService.getAllOneTwoSubject();
        return ResultAjax.success().data("list",list);
    }
}

